<!doctype html>
<html>
<head>
    <meta charset="UTF-8"/>
    <title>email发送记录</title>
    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">

    <script src="http://i.gtimg.cn/qzone/biz/gdt/lib/jquery/jquery-2.1.4.js?max_age=31536000"></script>

    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
    <script src='https://cdn.bootcss.com/jquery.form/4.2.2/jquery.form.min.js'></script>
    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/aliyun-oss-sdk.min.js"></script>
    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
</head>
<body>
<div class="easyui-container-fluid">
    <div class="easyui-panel" style="border: none;">
        <div class="nav" id="nav"></div>
        <div class="easyui-panel" style="border:none;">
            <form id="ff">
                <!--<div style="margin-bottom:20px;">-->
                    <!--<label class="item-label">发送时间段：</label>-->
                    <!--<input  id="startSedTime" name="startSedTime"  class="easyui-datetimebox"   data-options="required:true" style="width: 180px;">&#45;&#45;-->
                    <!--<input id="endSedTime"  name="endSedTime" data-options="required:true"  class="easyui-datetimebox" style="width: 180px;">-->
                    <!--<label class="item-label">状态：</label>-->
                    <!--<input id="entityStatus" class="easyui-switchbutton" checked style="width:80px;height:30px;" onText="启用" offText="禁用"  >-->
                    <!--<a href="javascript:void(0);" class="easyui-linkbutton c8" onclick="searchBy()" style="width:80px;margin-left: 40px;">查询</a>-->
                <!--</div>-->
                <div style="margin-bottom:20px;">
                    <label class="item-label">年份：</label>
                    <input type="text" id="year" name="year" class="easyui-combobox" style="width: 100px;"/>
                    <label class="item-label">报告模式：</label>
                    <select  name="recordMode" class="easyui-combobox" id="recoedMode"data-options="panelHeight:'auto'" style="width:100px;">
                        <option value="OFFLINE">线下</option>
                        <option value="ONLINE">线上</option>
                    </select>
                    <label class="item-label">报告类型：</label>
                    <select  name="reportType" class="easyui-combobox"id="reportType" data-options="panelHeight:'auto'" style="width:100px;">
                        <option value="MONTH">月度报</option>
                        <option value="WEEK" selected>周度报</option>
                        <option value="QUARTER">季度报</option>
                        <option value="HYEAR">半年报</option>
                    </select>

                    <span id="monthLabel">
	                         <label class="item-label">月份：</label>
	                         <input type="text" class="easyui-combobox" name="month" id="month" style="width:100px;"/></span>
                    <span id="weekLabel">
	                         <label class="item-label">周数：</label>
	                         <input type="text" class="easyui-combobox" name="week" id="week"  style="width:100px;"/></span>
                    <span id="quarterLabel">
	                         <label class="item-label">季数：</label>
                            <select  name="q" class="easyui-combobox"  data-options="panelHeight:'auto'" style="width:100px;">
                                <option value="FIRSTQUARTER">第一季度</option>
                                <option value="SECONDQUARTER">第二季度</option>
                                <option value="YHIRDQUARTER">第三季度</option>
                                <option value="FOURTHQUARTER">第四季度</option>
                            </select>
                    </span>
                    <span id="yearLabel">
	                         <label class="item-label">半年数：</label>
	                          <select  name="y" class="easyui-combobox"  data-options="panelHeight:'auto'" style="width:100px;">
                                <option value="FIRSTHALF">上半年</option>
                                <option value="SEONDHALF">下半年</option>
                            </select>
                    </span>
                    <label class="item-label">状态：</label>
                    <input id="entityStatus" class="easyui-switchbutton" checked style="width:80px;height:30px;" onText="启用" offText="禁用"  >
                    <a href="javascript:void(0);" class="easyui-linkbutton c8" onclick="searchBy()" style="width:80px;margin-left: 40px;">查询</a>
                </div>
            </form>
        </div>
        <div class="table-wrapper">
            <table id="datagrid" data-options="fitColumns:true,scrollBarSize:0">
                <thead>
                <tr>
                    <!--<th data-options="field:'year',align:'center'" width="30">年份</th>-->
                    <!--<th data-options="field:'week',align:'center', formatter:ymwj" width="30" >时间</th>-->
                    <!--<th data-options="field:'recordMode',align:'center'" width="40">报告模式</th>-->
                    <!--<th data-options="field:'reportType',align:'center'" width="40">报告类型</th>-->
                    <th data-options="field:'principalCode',align:'center'" width="80">负责人代码</th>
                    <th data-options="field:'company',align:'center'" width="100">公司名称</th>
                    <th data-options="field:'principalName',align:'center'" width="80">负责人</th>
                    <th data-options="field:'title',align:'center'" width="100">标题</th>
                    <th data-options="field:'content',align:'center'" width="150">内容</th>
                    <th data-options="field:'proportion',align:'center'" width="100">包含品类</th>
                    <th data-options="field:'sendTime',align:'center'" width="100">发送时间</th>

                    <th data-options="field:'emailStatus',align:'center',formatter:truefalse"  width="60">发送状态</th>
                    <th data-options="field:'operateUser',align:'center'" width="80">操作人</th>
                    <!--<th data-options="field:'entityStatus',align:'center',formatter:statusFormatter" width="40">状态</th>-->
                    <!--<th data-options="field:'action',align:'center',formatter:actions" width="160">操作</th>-->
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    var id;
    function initPage(){
        // searchBy(1,100);
    }
    $(function(){
        id=getQueryParameter("id");
        initYearSelect("year");
        initMonthSelect("month");
        initWeekSelect("week");
        // initCategorySelectnew("categorySelect");
        // initMonthWeek("monthLabel","weekLabel");
        // $("#weekLabel").hide();
        $("#monthLabel").hide();
        $("#quarterLabel").hide();
        $("#yearLabel").hide();
        $("#reportType").combobox({
            onChange:function(n,o){
                //这里的参数n是select改变后的value,o是改变前的value
                if(o =="MONTH" ){
                    // recordMode="MONTH";
                    $("#monthLabel").hide();
                }else if (o == "WEEK"){

                    $("#weekLabel").hide();
                }else if(o == "QUARTER"){
                    $("#quarterLabel").hide();
                }else if(o == "HYEAR"){
                    $("#yearLabel").hide();
                }

                if(n =="MONTH" ){
                    $("#monthLabel").show();
                }else if (n == "WEEK"){
                    $("#weekLabel").show();
                }else if(n == "QUARTER"){
                    $("#quarterLabel").show();
                }else if(n == "HYEAR"){
                    $("#yearLabel").show();
                }
                // alert(n);
            }
        });
        var height = $(window).height();
        var nav_height = $("#nav")._outerHeight();
        var ff_height = $("#ff").height();
        var table_height = height-nav_height-ff_height-40;
        $("#datagrid").css("max-height",table_height);
        $("#datagrid").datagrid({
            rownumbers:true,
            pagination:true,
            idField:"id",
            checkOnSelect:false,
        }).datagrid("getPager").pagination({
            onSelectPage:searchBy
        });
        initPage();
    });

    function searchBy(page,size) {
        /*var v1=$('#startSedTime').datetimebox("getValue");
        var startSedTime = new Date(v1);
        var v2=$('#endSedTime').datetimebox("getValue");
        var endSedTime = new Date(v2);
        if(v1=='') {
            alert("开始时间不能为空")
        }else if(v2=''){
            alert("结束时间不能为空")
        }else if(startSedTime>endSedTime){
            alert("开始时间不能大于结束时间")
        }else{*/

        var dtd = $.Deferred();
        var data = getFormData(document.getElementById("ff"));
        if (data.reportType == "MONTH") {
            data.mw = data.month;
        } else if(data.reportType == "WEEK"){
            data.mw = data.week;
        }else if(data.reportType == "QUARTER"){
            data.qy = data.q;
        }else if(data.reportType == "HYEAR"){
            data.qy = data.y;
        }else{
            console.log("报告类型为空");
        }
        console.log(data);
        var pager = {page:page,size:size};
        if(!size){
            pager['page']= 1;
            pager['size'] = $("#datagrid").datagrid("getPager").pagination("options").pageSize||100;
        }

        var jsonobj = {};
        jsonobj.entityStatus = $("#entityStatus").switchbutton("options").checked==true?"OK":"DISABLE";
        jsonobj = $.extend(true,jsonobj,transfer(data));
        jsonobj = JSON.stringify(jsonobj);

        $.ajax({
            url:config.url +  "/emailReceiving/pageRecording?"+transfer2url(pager),
            type:'post',
            data:jsonobj,
            contentType:"application/json;charset=UTF-8",
            dataType:'json',
            xhrFields:{withCredentials:true},
            beforeSend:function () {
                $.messager.progress({
                    title:"请稍等",
                    interval:50,
                    text:"数据加载中..."
                });
            },
            complete:function () {
                $.messager.progress("close");
            },
            success:function (data) {
                $.messager.progress("close");
                if(data){
                    globalData = data;
                    $("#datagrid").datagrid("loadData",data);
                    dtd.resolve();
                }
            },
            error:function (XMLHttpRequest,textStatus,errorThrown) {

            }
        });
        return dtd.promise();
    }

    function truefalse(val,row){
        if(row.emailStatus){
            return "是";
        }else{
            return "否"
        }
    }
    function ymwj(val,row){
        if(null != row.qy&& row.qy =="FIRSTQUARTER"){
            return "第一季度";
        }else  if(null != row.qy&& row.qy =="SECONDQUARTER"){
            return "第二季度";
        }else  if(null != row.qy&& row.qy =="YHIRDQUARTER"){
            return "第三季度";
        }else  if(null != row.qy&& row.qy =="FOURTHQUARTER"){
            return "第四季度";
        }else  if(null != row.qy&& row.qy =="FIRSTHALF"){
            return "上半年";
        }else  if(null != row.qy&& row.qy =="SEONDHALF"){
            return "下半年";
        }else  if(null != row.mw){
            return row.mw+"月/周";
        }
    }
</script>
<!--
<script type="text/javascript" src="/webapp/js/common/pagelist.js"></script>
-->
<script type="text/javascript">

    function updateStatus(id,entityStatus){
        $.messager.confirm("提示","您确定禁用/启用吗？",function (f) {
            if(f){
                $.ajax({
                    url:config.url+"/dmReference/"+id,
                    type:"DELETE",
                    dataType:"json",
                    data:JSON.stringify(id),
                    contentType:"application/json;charset=UTF-8",
                    xhrFields:{withCredentials:true},
                    beforeSend:function () {
                        $.messager.progress({
                            title:"请稍等",
                            interval:50,
                            text:"操作进行中..."
                        });
                    },
                    complete:function () {
                        $.messager.progress("close");
                        $.messager.alert("提示","操作成功","info",function () {
                            searchBy(1,100);
                        });
                    },
                    success:function (data) {
                        $.messager.alert("提示","操作成功","info",function () {
                            searchBy(1,100);
                        });
                    },
                    error:function (data) {

                    }
                });
            }
        });
    }

    function validateDateTime(beginTimeId,endTimeId,whichTimeId)
    {
        console.log("hello world");
        var v1=$('#'+beginTimeId).datetimebox("getValue");
        var date1 = new Date(v1);
        var v2=$('#'+endTimeId).datetimebox("getValue");
        var date2 = new Date(v2);

        if(v1==''||v2=='')
        {
            return true;
        }
        console.log(date1);
        console.log(date2);
        if(date1<date2)
        {
            console.log(date1+"<"+date2);
            var diff=DateDiff(date1,date2);
            if(diff>30)
            {
                $.messager.alert('提示','时间段不能超过30天！');
                $('#'+whichTimeId).datetimebox("setValue","");
            }
            return true;
        }
        console.log(date1+"!<"+date2);
        try{
            $('#'+whichTimeId).datetimebox("setValue","");
        }catch(e){
        }
        try{
            $('#'+whichTimeId).datebox("setValue","");
        }catch(e){
        }

        $.messager.alert('提示','开始时间要小于结束时间！');

        return false;
    }

</script>
</html>
